package class101To110;

import java.io.*;

public class IndexTreeIntervalAddIntervalQuery {

    public static int MAX_N = 100005;

    public static long[] info1 = new long[MAX_N];
    public static long[] info2 = new long[MAX_N];

    public static int n, m, op;

    public static int lowBit(int x) {
        return x & (-x);
    }

    public static void add(long[] tree, int i, long x) {
        while (i <= n) {
            tree[i] += x;
            i += lowBit(i);
        }
    }

    public static long getSum(long[] tree, int i) {
        long ans = 0;
        while (i > 0) {
            ans += tree[i];
            i -= lowBit(i);
        }
        return ans;
    }

    public static void add(int l, int r, long x) {
        add(info1, l, x);
        add(info1, r + 1, -x);
        add(info2, l, (l - 1) * x);
        add(info2, r + 1, -(r * x));
    }


    public static long query(int l, int r) {
        return getSum(info1, r) * r - getSum(info2, r) - getSum(info1, l - 1) * (l - 1) + getSum(info2, l - 1);
    }


    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(br));
        PrintWriter out = new PrintWriter(System.out);
        while (in.nextToken() != StreamTokenizer.TT_EOF) {
            n = (int) in.nval;
            in.nextToken();
            m = (int) in.nval;
            long cur;
            for (int i = 1; i <= n; i++) {
                in.nextToken();
                cur = (long) in.nval;
                add(i, i, cur);
            }
            for (int i = 1; i <= m; i++) {
                in.nextToken();
                op = (int) in.nval;
                if (op == 1) {
                    in.nextToken();
                    int l = (int) in.nval;
                    in.nextToken();
                    int r = (int) in.nval;
                    in.nextToken();
                    cur = (long) in.nval;
                    add(l, r, cur);
                } else {
                    in.nextToken();
                    int l = (int) in.nval;
                    in.nextToken();
                    int r = (int) in.nval;
                    out.println(query(l, r));
                }
            }
        }
        out.flush();
        out.close();
        br.close();
    }
}
